<template>
  <div class="good">
    <MyHeader :title="title"></MyHeader>
    <MyTable :list="list">
      <template #head>
        <th>#</th>
        <th>商品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>操作</th>
      </template>
      <template #body="scope">
        <td>{{ scope.row.id }}</td>
        <td>{{ scope.row.goods_name }}</td>
        <td>{{ scope.row.goods_price }}</td>
        <td
          v-for="item in scope.row.tags"
          :key="item"
          class="badge bg-warning text-dark"
        >
          {{ item }}
        </td>
        <td>
          <button @click="del(scope.row.id)" class="btn btn-danger btn-sm">
            删除
          </button>
        </td>
      </template>
    </MyTable>
  </div>
</template>

<script>
import MyTable from "../components/MyTable";
import MyHeader from "../components/MyHeader.vue";

export default {
  components: {
    MyTable,
    MyHeader,
  },
  data() {
    return {
      list: [], // 所有数据
      title: "案例",
    };
  },
  async created() {
    let res = await this.$money({
      url: "/api/goods",
    });
    this.list = res.data.data;
    // console.log(this.list);
  },
  methods: {
    del(id) {
      let index = this.list.findIndex((item) => item.id == id);
      this.list.splice(index, 1);
    },
  },
};
</script>
<style lang="less">
.good {
  padding-top: 45px;
}
</style>